package castle.defense.project;

import android.graphics.RectF;
/**
 * The engine driving all of the physics translations that will occur for the game.
 * Handles the Physics and Collisions of all in game objects.
 * 
 * @author Daniel Wasserman
 *
 */
public class PE {
	// the abstract size of the screen (50 x 50) meters
	//size of the "meter" field in (x X y) meters
	public static double sizeX=500,sizeY=500;
	public static boolean set = false;
	
	public static void setBounds(double w, double h)
	{
		set = true;
		sizeX = w;
		sizeY = h;
	}
	public static boolean collision(PhysicsPoint a, PhysicsPoint b, double r1, double r2) {
		return a.getDistance(b) < r1+r2+1e-9;
	}
	public static RectF screenRegion(double x1, double y1, double x2, double y2) {
		return new RectF(toScreenX(x1),toScreenY(y1),toScreenX(x2),toScreenY(y2));
	}
	public static boolean onScreen(double x, double y) {
		return !(x<0||y<0||x>sizeX||y>sizeY);
	}
	public static boolean onScreen(PhysicsPoint p) {
		return onScreen(p.getX(),p.getY());
	}
	
	public static RectF regionByPercent(double x1p, double y1p, double widthp, double heightp) {
		return screenRegion(screenPercentX(x1p), screenPercentY(y1p), screenPercentX(widthp+x1p), screenPercentY(y1p-heightp));
	}
	
	public static boolean onScreen(double x, double y, double r) {return !(x+r<0 ||y+r<0||y-r>sizeY||x-r>sizeX);}
	public static boolean onScreen(PhysicsPoint p, double r) {return onScreen(p.getX(),p.getY(),r);}
	
	public static float toScreenX(double x) {return (float) (x);}
	public static float toScreenY(double y) {return (float)(sizeY - y);}
	public static double toMetersX(double x) {return x;}
	public static double toMetersY(double y) {return (sizeY-y);}
	
	
	/**
	 * returns the number of meters that equates to percent % of the screen
	 * @param percent
	 * @return 
	 */
	public static double screenPercentY(double percent) {
		return (percent/100.0) * sizeY;
	}
	
	/**
	 * 
	 * @param percent The percentage of the width of the screen being asked for.
	 * @return the number of meters that the percentage "percent" is
	 */
	public static double screenPercentX(double percent) {
		return (percent/100.0) * sizeX;
	}
}
